package com.cortex.pineapple.adapters;

import java.util.ArrayList;
import java.util.List;

import com.cortex.pineapple.R;
import com.cortext.pineapple.link.ImageLink;
import com.cortext.pineapple.link.Link;
import com.cortext.pineapple.link.VideoLink;
import com.cortext.pineapple.link.WebLink;
import com.cortext.pineapple.link.Link.OnDataChangedListener;
import com.squareup.picasso.Picasso;

import android.content.Context;
import android.provider.MediaStore.Video;
import android.text.SpannableString;
import android.text.style.UnderlineSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;


public class VideoAdapter extends LinkAdapter<VideoLink> {

	public VideoAdapter(Context context) {
		super(context);
		links = new ArrayList<VideoLink>();
	}
	public VideoAdapter(Context context, List<VideoLink> links) {
		super(context,links);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		VideoLink link = links.get(position);
		ViewGroup linkView = (ViewGroup) convertView; 
		if(linkView == null){
			LayoutInflater inflater = LayoutInflater.from(context);
			linkView = (ViewGroup) inflater.inflate(R.layout.view_video_link, null);
		}
		buildItemView(link, linkView);

		return linkView;
	}
	@Override
	protected void buildItemView(VideoLink link, ViewGroup linkView) {
		// add under line 
		TextView titleText = (TextView) linkView.findViewById(R.id.title);
		SpannableString title = new SpannableString(link.getTitle());
		title.setSpan(new UnderlineSpan(), 0, title.length(), 0);
		titleText.setText(title);

		((TextView)linkView.findViewById(R.id.url)).setText(link.getUrl());

		Picasso.with(context)
		.load(link.getImageUrl())
		.resizeDimen(R.dimen.videoImageWidth,R.dimen.videoImageHeight)
		.noFade()
		.into((ImageView)linkView.findViewById(R.id.image));
	}

}
